<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreatePayRecordTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pay_record', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('order_sn')->nullable(false)->comment("业务系统订单号");
            $table->integer("amount")->default(0)->comment("交易金额(分)");
            $table->string("subject")->nullable(false)->comment("支付科目");
            $table->string("items",1024)->nullable()->comment("支付项目");
            $table->string("pay_method")->nullable(false)->comment("支付方式");
            $table->tinyInteger("state")->default(0)->comment("支付状态");
            $table->string('out_trade_no')->nullable(false)->comment("外部系统支付单号");
            $table->unsignedInteger("create_time")->default(0)->comment("创建时间");
            $table->unsignedInteger("payment_time")->default(0)->comment("支付时间");
            $table->unsignedInteger("produce_time")->default(0)->comment("消息生产时间");
            $table->unsignedInteger("cancel_time")->default(0)->comment("取消时间");

            $table->comment("支付记录表");
            $table->index(["order_sn"],"idx_order_sn","BTREE");
            $table->index(["out_trade_no"],"idx_out_trade_no","BTREE");
            $table->index(["payment_time"],"idx_payment_time","BTREE");
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pay_record');
    }
}
